/**
 * Created by Administrator on 2017/10/10
 */
import React from 'react';
import {WeaTableNew} from 'comsMobx';
import {WeaSearchGroup, WeaLocaleProvider} from 'ecCom';
import {Button,Icon} from 'antd';

const getLabel = WeaLocaleProvider.getLabel;

const WeaTable = WeaTableNew.WeaTable;

export default class Main extends React.Component{

    constructor(props){
        super(props);
    }

    deleteConfirm () {
        const ids = this.getSelectedRowKeysTail();
        this.props.deleteConfirm(ids);
    }

    getSelectedRowKeysTail(){
        const { tableStore } = this.props;
        const tableNow = tableStore;
        const selectedRowKeys = tableNow.selectedRowKeys;
        const idsJson = JSON.stringify(selectedRowKeys);
        let ids = idsJson.slice(1,idsJson.length-1).replace(/\"/g,"");
        return ids;
    }

    addShare () {
        this.props.addShare();
    }

    render(){
        let customComponent = '';
        const { jurisdiction, tableStore, title } = this.props;
        if (jurisdiction){
            customComponent = <CustomComponent ecId={`${this && this.props && this.props.ecId || ''}_CustomComponent@xlcnkj`} ids={()=>this.props.ids()} deleteConfirm={()=>this.deleteConfirm()} addShare={()=>this.addShare()} />;
        }
        return(
            <div className="wf-searchGroup">
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@zn83d2`}
                    col={1}
                    title={title}
                    showGroup={true}
                    customComponent={customComponent}
                    items={[
                        {
                            com:
                            this.props.onOperatesClick ?
                                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@0qh441@workflowShare`}
                                    onOperatesClick={(record,index,operate,flag)=>{this.props.onOperatesClick(record,index,operate,flag)}}
                                    comsWeaTableStore={tableStore}
                                    hasOrder={true}
                                    needScroll={true}
                                    scroll={{y:600}}
                                />
                                :
                                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@gxzycq@workflowShare`}
                                    comsWeaTableStore={tableStore}
                                    hasOrder={true}
                                    needScroll={true}
                                    scroll={{y:600}}
                                />
                        }
                    ]}
                />
            </div>
        )
    }
}

//头部操作按钮
class CustomComponent extends React.Component{
    constructor(props) {
        super(props);
    }

    addShare () {
        this.props.addShare()
    }

    deleteConfirm() {
        this.props.deleteConfirm()
    }
    render () {
        const ids = this.props.ids();
        return (
            <div className="customComponent">
                {/*<Button style={{padding:'0 3px',borderRadius:'0',marginLeft:'10px'}} type="primary" title='添加' size="small" onClick={() => this.addShare()}><Icon style={{color:'#fff'}} type="plus" /></Button>*/}
                {/*<Button style={{padding:'0 3px',borderRadius:'0',marginLeft:'10px',backgroundColor: !ids && '#d8d8d8' }} type="primary" title='删除' size="small" disabled={!ids} onClick={() => this.deleteConfirm()} ><Icon style={{color:'#fff'}} type="minus" /></Button>*/}

                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@7qcbpk`} style={{border:'none',padding:'0px',fontSize:'20px',lineHeight:'1',color:'#55a1f8',backgroundColor:'#fff'}} type="primary" title={getLabel(611,'添加')} size="small" onClick={() => this.addShare()}><span className="icon-coms-Add-to-hot"/></Button>
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@1xtnao`} style={{border:'none',padding:'0px',fontSize:'20px',lineHeight:'1',color: !ids ? '#d8d8d8':'#55a1f8',marginLeft:'10px',backgroundColor: '#fff'}} type="primary" title={getLabel(126371,'删除')} size="small" disabled={!ids} onClick={() => this.deleteConfirm()} ><span className="icon-coms-form-delete-hot"/></Button>

            </div>
        )
    }
}

